
#ifndef __DATA_ACCESS_H__
#define __DATA_ACCESS_H__

#include <string>
#include <vector>
#include <mysql.h>
#include <time.h>

#include "tble.h"

using namespace std;

class CDataAccess
{
public:
    CDataAccess();
    CDataAccess(MYSQL *sock);
    ~CDataAccess();

    MYSQL* GetConnentHandle();
    const char* GetLastErrorString();
    int GetLastErrno();

    inline string& GetSql()
    {
        return m_sSql;
    }

    inline unsigned long GetAffectedRowsCount()
    {
        return mysql_affected_rows(m_mysqlSock);
    }

    inline unsigned long GetInsertId()
    {
        return mysql_insert_id(m_mysqlSock);
    }

    int Connect(const string &sHost, const string &sUser, const string &sPwd, const string &sDatabase);
    int DisConnect();
    int SwitchDB(const string& sDBName);
    int Command(const string &sSql);
    int AddParameters(const string &sPara, const string &sValue);
    int AddParameters(const string &sPara, int iValue);
    int AddParameters(const string &sPara, unsigned int uiValue);
    int AddParameters(const string &sPara, unsigned long uiValue);
    int AddParameters(const string &sPara, char cValue);
    int Execute();
    int Execute(CDataTable &table);

private:
    MYSQL *m_mysqlSock;
    bool m_bConnected;
    string m_sSql;

};

#endif
